package com.quanyan.place.web.api;

import com.quanyan.api.APIResponse;
import com.quanyan.api.enums.ApiResponseEnum;
import com.quanyan.place.entity.apireq.ReqPlaceBaseInfo;
import com.quanyan.place.entity.apireq.ReqPlaceSalePlan;
import com.quanyan.place.entity.apiresp.RespPlaceClubActivity;
import com.quanyan.place.service.ApiPlaceOrderService;
import com.quanyan.place.wrapper.PlaceWrapper;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Map;

/**
 * 新版订场及门票接口
 * Created by zhaohui on 2016/11/24.
 */
@RestController
@RequestMapping("/api/place/order")
public class ApiPlaceOrderController {

    @Autowired
    ApiPlaceOrderService apiPlaceOrderSerive;
    @Autowired
    PlaceWrapper placeWrapper;
    /**
     * 订场
     * @param reqPlaceSalePlan
     * @return
     */
    @RequestMapping(value = "/placeSalePlan",method = RequestMethod.POST,produces = {"application/json; charset=UTF-8"})
    public APIResponse<?> placeSalePlan(@RequestBody @Valid ReqPlaceSalePlan reqPlaceSalePlan,
                                          BindingResult bindingResult){
        if (bindingResult.hasErrors()) {
            return APIResponse.returnFail(ApiResponseEnum.PARAMETER_INVALID);
        }

       // return apiPlaceOrderSerive.getPlaceSalePlan(reqPlaceSalePlan);
        return placeWrapper.getPlaceSalePlan(reqPlaceSalePlan);
    }

    /**
     * 获取场馆基本信息
     * @param reqPlaceBaseInfo
     * @param bindingResult
     * @return
     */
    @RequestMapping(value = "/getPlaceBaseInfo",method = RequestMethod.POST,produces = {"application/json; charset=UTF-8"})
    public APIResponse<?> getPlaceBaseInfo(@RequestBody @Valid ReqPlaceBaseInfo reqPlaceBaseInfo,
                                           BindingResult bindingResult){
        if (bindingResult.hasErrors()) {
            return APIResponse.returnFail(ApiResponseEnum.PARAMETER_INVALID);
        }
        return apiPlaceOrderSerive.getPlaceBaseInfo(reqPlaceBaseInfo.getPlaceId());
    }

	/**
     * 场内精彩
     * @param map
     * @param bindingResult
     * @return
     */
    @RequestMapping(value = "/getPlaceClubInfo",method = RequestMethod.POST,produces = {"application/json; charset=UTF-8"})
    public APIResponse<?> getPlaceClubInfo(@RequestBody @Valid Map<String, Object> map, BindingResult bindingResult){
        if (bindingResult.hasErrors()) {
            return APIResponse.returnFail(ApiResponseEnum.PARAMETER_INVALID);
        }
        Integer placeId = MapUtils.getInteger(map, "placeId");
        if (null == placeId){
            return APIResponse.returnFail(ApiResponseEnum.PARAMETER_CANT_BE_EMPTY);
        }
        RespPlaceClubActivity respPlaceClubActivity = placeWrapper.findPlaceVC(placeId);
        return APIResponse.returnSuccess(respPlaceClubActivity);
    }
}
